
package botlab.control;

import botlab.Game;
import botlab.engine.physics.RayCast;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.Control;

/**
 *
 * @author Quentin
 */
public class TestControl extends BaseControl
{
    RayCast rc = new RayCast(Game.getApp().getCurrentLevel().getRayCastableNode(),new Node[]{});
    Node dirNode = new Node();

    @Override
    protected void controlUpdate(float tpf)
    {
        //this.getSpatial().rotate(0, 2*tpf, 0);
        Vector3f direction;
        direction = this.getSpatial().getLocalRotation().mult(Vector3f.UNIT_Z);
        rc.rayCastFromPoint(this.getSpatial().getLocalTranslation(), direction);
        Game.getText().setText(String.valueOf(rc.getDistance()));
        
        //test de la distance de l'objet détecté
        if(rc.getDistance()>0 && rc.getDistance()<5)
        {
            spatial.setLocalTranslation(spatial.getLocalTranslation().add(
                    spatial.getLocalRotation().mult(Vector3f.UNIT_Z.mult(tpf))));
        }
    }

    @Override
    public Control cloneForSpatial(Spatial spatial)
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
